package com.world.blog.factory;

import cn.hutool.extra.spring.SpringUtil;
import com.world.blog.service.IBlogArticleService;
import com.world.blog.service.IBlogProjectService;
import com.world.common.constant.CacheConstants;
import com.world.common.core.redis.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @Author: LiJunXi
 * @Description:
 * @Date: 2025-05-28  21:31
 */
@Component
public class BlogAsyncManager {

    @Autowired
    private RedisCache redisCache;


    @Async(value = "threadPoolTaskExecutor")
    public void addArticleViewsCount(Long articleId) {
        Integer viewsCount = SpringUtil.getBean(IBlogArticleService.class).getArticleViewsCount(articleId);
        redisCache.setCacheObject(CacheConstants.BLOG_ARTICLE_VIEWS_COUNT + articleId, viewsCount + 1);
    }


    @Async(value = "threadPoolTaskExecutor")
    public void addProjectViewsCount(Long projectId) {
        Integer viewsCount = SpringUtil.getBean(IBlogProjectService.class).getProjectViewsCount(projectId);
        redisCache.setCacheObject(CacheConstants.BLOG_PROJECT_VIEWS_COUNT + projectId, viewsCount + 1);
    }

}
